﻿<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../demo.css">
	<script type="text/javascript" src="../jquery.min.js"></script>
	<script type="text/javascript" src="../jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../extend.js"></script>
	<script type="text/javascript" src="../jquery.cookie.js"></script>
    <script>
        var dataListCache = null;
        var dataCache = null;
        var appId = GetQueryString("moduleid");
        window.onresize=calSize;
        $(document).ready(function(){
            setData();
            calSize();
		});
        function setData(){
            $.get("../../api/fiscalperiod/getbysite", function (data) {if(data.Result==0){dataCache = JSON.parse(data.Data)[0];initVal();}else{alert('err');}},"json");
        }
        window.onresize=calSize;
        function calSize(){
            var height=window.parent.document.getElementById("mainFrame").clientHeight;
            var width=window.parent.document.getElementById("mainFrame").clientWidth;
            window.parent.document.getElementById(appId).height = height-32;
            $("#toolbar").panel({width:width-15});
            $("#editToolbar").panel({width:width-15});
            $("#editZone").panel('resize',{height:height-76,width:width-15});
        }
        
        function initVal(){
            $('#AutoId').val(dataCache.AutoId);
            $('#Flag').val(dataCache.Flag);
            $('#Site').val(dataCache.Site);
			$('#State').val(dataCache.State);
            $('#Code').textbox("setValue",dataCache.Code);
            $('#Name').textbox("setValue",dataCache.Name);
			$("#OpenDate").datebox("setValue", dataCache.OpenDate);
            $("#DueDate").datebox("setValue", dataCache.DueDate);
        }
        function editRecord(rowIndex,rowData){
            dataCache = rowData;
            initVal();
            $('#editContent').window('open');
        }
        function submitChange(){
            if (dataCache == null) {
                $.messager.alert("错误", "无法获取被编辑的对象", "error");
                return;
            }
            showMask();
			var oldData = JSON.parse(JSON.stringify(dataCache));
            dataCache.Flag = $("#Flag").val();
			dataCache.State = $("#State").val();
            dataCache.Code=$("#Code").textbox("getValue");
            dataCache.Name=$("#Name").textbox("getValue");
			dataCache.OpenDate=$("#OpenDate").datebox("getValue");
            dataCache.DueDate=$("#DueDate").datebox("getValue");
            $.post("../../api/fiscalperiod/set",dataCache,function(response){
                if(response.Result==0){
                    dataCache = JSON.parse(response.Data);
                    initVal();
                    $.messager.alert("信息","操作成功","info");
                }else{
                    $.messager.alert("错误",response.Message,"error");
					dataCache = oldData;
                }
            })
            .error(function(){
                $.messager.alert("错误","系统内部错误","error");
				dataCache = oldData;
            })
            .complete(function() { 
                hideMask();
            });
        }
        function boolFormatter(value,row,index){
            if(value){
                return "是";
            }else{
                return "否";
            }
        }
    </script>
<head>
<body onload = "hideMask()">
    <script>showMask('正在载入数据');</script>
    <div style="margin:2px"></div>
        <div class="easyui-panel" id="editToolbar" style="padding:1px;width:100%">
            <a href="#" class="easyui-linkbutton" data-options="onClick:submitChange,iconCls:'icon-save',plain:true">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="onClick:initVal,iconCls:'icon-no',plain:true">取消</a>
        </div>
        <div style="margin:2px"></div>
        <div id="editZone" class="easyui-panel" style="padding:4px 4px 0px 4px" >
            <table>
                <tr>
                    <td><input class="easyui-textbox" id="Code"  style="width:300px" data-options="label:'代号:',required:true"></td>
                    <td>&nbsp;</td>
                    <td><input class="easyui-textbox" id="Name"  style="width:300px" data-options="label:'名称:'"></td>
				</tr>
                <tr>
                    <td><input class="easyui-datebox" id="OpenDate" style="width:300px" data-options="label:'开始日期:',formatter:dateFormatter,parser:dateParser"></td>
                    <td>&nbsp;</td>
                    <td><input class="easyui-datebox" id="DueDate" style="width:300px" data-options="label:'结束日期:',formatter:dateFormatter,parser:dateParser"></td>
                </tr>
            </table>
            <div hidden>
                <p id="AutoId"></p>
                <p id="Flag"></p>
                <p id="Site"></p>
                <p id="State"></p>
            </div>
        </div>
</body>
</html>